package com.lvy.hczn.front.business.controller;

import java.util.List;

import com.lvy.hczn.front.system.domain.business.TemperatureZone;
import com.lvy.hczn.front.system.service.TemperatureZoneService;
import com.lvy.hczn.front.system.service.WarehouseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.common.core.page.TableDataInfo;

/**
 * 温区信息Controller
 *
 * @author ruoyi
 * @date 2023-05-27
 */
@Controller
@RequestMapping("/system/zone")
public class TemperatureZoneController extends BaseController {
    private String prefix = "system/zone";

    @Autowired
    private TemperatureZoneService temperatureZoneService;

    @Autowired
    private WarehouseService warehouseService;

    @RequiresPermissions("system:zone:view")
    @GetMapping()
    public String zone() {
        return prefix + "/zone";
    }

    /**
     * 查询温区信息列表
     */
    @RequiresPermissions("system:zone:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TemperatureZone temperatureZone) {
        startPage();
        List<TemperatureZone> list = temperatureZoneService.selectTemperatureZoneList(temperatureZone);
        return getDataTable(list);
    }

    /**
     * 导出温区信息列表
     */
    @RequiresPermissions("system:zone:export")
    @Log(title = "温区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TemperatureZone temperatureZone) {
        List<TemperatureZone> list = temperatureZoneService.selectTemperatureZoneList(temperatureZone);
        ExcelUtil<TemperatureZone> util = new ExcelUtil<TemperatureZone>(TemperatureZone.class);
        return util.exportExcel(list, "温区信息数据");
    }

    /**
     * 新增温区信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存温区信息
     */
    @RequiresPermissions("system:zone:add")
    @Log(title = "温区信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TemperatureZone temperatureZone) {
        return toAjax(temperatureZoneService.insertTemperatureZone(temperatureZone));
    }

    /**
     * 修改温区信息
     */
    @RequiresPermissions("system:zone:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        TemperatureZone temperatureZone = temperatureZoneService.selectTemperatureZoneById(id);
        mmap.put("temperatureZone", temperatureZone);
        return prefix + "/edit";
    }

    /**
     * 修改保存温区信息
     */
    @RequiresPermissions("system:zone:edit")
    @Log(title = "温区信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TemperatureZone temperatureZone) {
        warehouseService.updateToTransmitByTemperatureZoneChanged(temperatureZone);
        return AjaxResult.success();
    }

    /**
     * 删除温区信息
     */
    @RequiresPermissions("system:zone:remove")
    @Log(title = "温区信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(temperatureZoneService.deleteTemperatureZoneByIds(ids));
    }
}
